/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import io from '@/module/io'

export default {
/**
   * role all  list
   */
  getRoleList ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.get('role/pageList', payload, res => {
        resolve(res.data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  /**
   * role all  list
   */
  getRoleAll ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.get('role/listAll', payload, res => {
        resolve(res.data)
      }).catch(e => {
        reject(e)
      })
    })
  },
  /**
   * create role
   * @param "id":int,
   * @param "roleName":string,
   * @param "roleComment": string,
   * @param "tenantId":int,
   */
  createRole ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.post('role/create', payload, res => {
        resolve(res)
      }, (res) => { }, { emulateJSON: false }).catch(e => {
        console.log(e)
        reject(e)
      })
    })
  },
  /**
   * Update role
   * @param "id":int,
   * @param "roleName":string,
   * @param "roleComment": string,
   * @param "tenantId":int,
   */
  updateRole ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.post('role/update', payload, res => {
        resolve(res)
      }, {}, { emulateJSON: false }).catch(e => {
        reject(e)
      })
    })
  },
  /**
   * delete role
   * @param "id":int
   */
  deleteRole ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.delete('role/delete', payload, res => {
        resolve(res)
      }).catch(e => {
        reject(e)
      })
    })
  },

  /**
   * 查询角色关联的用户
   */
  findRoleUser ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.get('role/findUser', payload, res => {
        resolve(res)
      }).catch(e => {
        reject(e)
      })
    })
  },

  /**
   * 查询角色的配置权限
   */
  getPermissions ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.get('role/getPermissions', payload, res => {
        resolve(res)
      }).catch(e => {
        reject(e)
      })
    })
  },

  saveAuth ({ state }, payload) {
    return new Promise((resolve, reject) => {
      io.post('role/auth', payload, res => {
        resolve(res)
      }, {}, { emulateJSON: false }).catch(e => {
        reject(e)
      })
    })
  }

}
